package com.nd.qa.shareplate.message;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.nd.qa.shareplate.model.ShareScript;
import com.nd.qa.shareplate.service.ShareScriptService;
import com.nd.qa.shareplate.util.FileTool;

public class FtpElearningTask {

	private String remoteIp = "192.168.70.90";
	private int port = 21;
	private String userName = "administrator";
	private String password = "5rft%";
	
	@Autowired
	private ShareScriptService shareScriptService;
	
	public void autoRun(){
		new Thread(){
			public void run() {
				//项目类型(厦门项目)
				List<String> projectType = new ArrayList<String>();
				projectType.add("45");
				projectType.add("46");
				projectType.add("49");
				//取出文件存储地址，并依次推送到服务器
				for (int j = 0; j < projectType.size(); j++) {
					ShareScript script = new ShareScript();
					script.setUserId("865579");
					script.setPlatformType(1);
					script.setProjectType(projectType.get(j));
					script.setStatus("A");
					try {
						List<ShareScript> lists = shareScriptService.queryScripts(script);
						int i = 0 ;
						for(ShareScript list:lists){
							i++;
							String filePath = "";
							System.out.println("name==="+list.getClassName());
							if (list.getClassName()!=null) {
								filePath = list.getLocalScriptUrl()+File.separator+list.getClassName()+".java";
								File file = new File(filePath);
								if (file.exists()) {
									FileTool.upLoadFromProduction(remoteIp, port,userName, password, "D:"+File.separator+"auto+"+File.separator+"+macaca+"+File.separator+"", list.getClassName()+".java", filePath);
								}
							}
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}.run();
	}
	
	
	public static void main(String[] args) {
		FtpElearningTask fTask = new FtpElearningTask();
		fTask.autoRun();
	}
}
